﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ZhimeiSoft.Framework.Common.MathUtils
{
    public class NumberUtil
    {
        public static bool IsNumber(string sNumber)
        {
            //看要用哪種規則判斷，自行修改strValue即可

            //string strValue = @"^\d+[.]?\d*$";//非負數字
            //strValue = @"^\d+(\.)?\d*$";//數字
            string strValue = @"^\d+$";//非負整數
            //strValue = @"^-?\d+$";//整數
            //strValue = @"^-[0-9]*[1-9][0-9]*$";//負整數
            //strValue = @"^[0-9]*[1-9][0-9]*$";//正整數
            //strValue = @"^((-\d+)|(0+))$";//非正整數

            Regex r = new Regex(strValue);
            return r.IsMatch(sNumber);
        }

        public static bool IsNonNegativeNumber(string sNumber)
        {
            string strValue = @"^[0-9]*[1-9][0-9]*$";//正整數
            Regex r = new Regex(strValue);
            return r.IsMatch(sNumber);
        }

        public static bool IsDecimal(string sDecimal)
        {
            bool bFlag = false;
            Regex regex = new Regex(@"^[-]?\d+[.]?\d*$");
            if (regex.IsMatch(sDecimal))
            {
                bFlag = true;
            }
            return bFlag;
        }

        public static bool IsNonNegativeDecimal(string sDecimal)
        {
            bool bFlag = false;
            Regex regex = new Regex(@"^\d+[.]?\d*$");
            if (regex.IsMatch(sDecimal))
            {
                bFlag = true;
            }
            return bFlag;
        }
    }
}
